home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / novia / src / start_rexx.c < prev    next >
C/C++ Source or Header  |  1999-12-06  |  4KB  |  188 lines

  1. /*
  2. **    $VER: start_rexx 37.0 (18.08.1998)
  3. **
  4. **    NOVIA interactive network services
  5. **
  6. **    (C) Copyright 1996-1998 Thorsten Gehler/UFoP
  7. **    All Rights Reserved
  8. */
  9.  
  10. char ver[]="$VER: start_rexx 37.0 ("__DATE__" "__TIME__").";
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <dos/dos.h>
  15. #include <exec/ports.h>
  16. #include <exec/memory.h>
  17. #include <pragma/exec_lib.h>
  18. #include <pragma/intuition_lib.h>
  19. #include <pragma/dos_lib.h>
  20. #include <novia/novia_message.h>
  21. #include <novia/novia_types.h>
  22.  
  23. void PrintDosError(const LONG errorcode)
  24. {
  25.     char buffer[82];
  26.     if (!Fault((LONG)errorcode,NULL,buffer,82))
  27.         strcpy(buffer,"\n");
  28.     printf("DOS-Error  %d: %s\n",errorcode,buffer);
  29. }
  30.  
  31. void main(int argc, char **argv)
  32. {
  33.     LONG returncode=20;
  34.     struct MsgPort *rexxport=0;
  35.     struct MsgPort *clientport=0;
  36.     struct MsgPort *replyport=CreateMsgPort();
  37.     ULONG ClientID=0;
  38.     char *ProgramName=0;
  39.     char tempfile[50];
  40.     char buffer[256];
  41.     struct message msg;
  42.     ULONG secs;
  43.     ULONG mics;
  44.     ULONG counter;
  45.     BPTR    in=NULL,
  46.             out=NULL;
  47. /*
  48. struct message
  49. {
  50.     struct     Message msg;
  51.     struct    message *ln_Succ;
  52.     struct    message *ln_Pred;
  53.     ULONG            IDNumber;
  54.     ULONG            IPNumber;        // serial number of message
  55.     ULONG            PortID;
  56.     ULONG            msg_type;
  57.     ULONG            cmd_type;        // if sending a command
  58.     APTR            data;
  59.     ULONG            data_len;        // length of data
  60. };
  61. */
  62.     if (argc>=3)
  63.     {
  64.         ProgramName=argv[2];
  65.         if ((StrToLong(argv[1],(LONG *)&ClientID)>-1) && (strlen(ProgramName)>0))
  66.         {
  67.             sprintf(buffer,"NOVIAREXX%d");
  68.             rexxport=FindPort(buffer);
  69.             if (ClientID)
  70.                 sprintf(buffer,"NOVIACLIENT%d");
  71.             else
  72.                 sprintf(buffer,"Novia_MainPort");
  73.             clientport=FindPort(buffer);
  74.             if (rexxport && clientport && replyport)
  75.             {
  76.                 CurrentTime(&secs,&mics);
  77.                 sprintf(tempfile,"ram:novia_rexx.%d.%d",ClientID,mics);
  78.                 if ((in=Open(ProgramName,MODE_OLDFILE)) && (out=Open(tempfile,MODE_NEWFILE)))
  79.                 {
  80.                     Seek(in,0,OFFSET_END);
  81.                     counter=Seek(in,0,OFFSET_BEGINNING);
  82.                     if (counter!=-1)
  83.                     {
  84.                         char *iobuffer;
  85.                         if (iobuffer=AllocVec(counter+1,MEMF_ANY))
  86.                         {
  87.                             if (Read(in,iobuffer,counter)==counter)
  88.                             {
  89.                                 sprintf(buffer,"/* NOVIA REXX PROGRAM */\naddress 'NOVIAREXX%d'\n",ClientID);
  90.                                 if (Write(out,buffer,strlen(buffer))!=-1)
  91.                                 {
  92.                                     if (Write(out,iobuffer,counter)!=-1)
  93.                                     {
  94.                                         Close(in);in=NULL;
  95.                                         Close(out);out=NULL;
  96.                                         FreeVec(iobuffer);iobuffer=NULL;
  97.                                         memset(&msg,0,sizeof(message));
  98.                                         msg.msg.mn_ReplyPort=replyport;
  99.                                         msg.msg.mn_Length=sizeof(message);
  100.                                         msg.msg_type=MSG_NREXX_START;
  101.                                         PutMsg(clientport,(Message *)&msg);
  102.                                         WaitPort(replyport);
  103.                                         if (msg.msg_type==MSG_NREXX_OK)
  104.                                         {
  105.                                             sprintf(buffer,"rx %s",tempfile);
  106.                                             if (Execute(buffer,0,0))
  107.                                             {
  108.                                                 msg.msg_type=MSG_NREXX_END;
  109.                                                 PutMsg(clientport,(Message *)&msg);
  110.                                                 WaitPort(replyport);
  111.                                             }
  112.                                             else
  113.                                             {
  114.                                                 printf("rexx execute error, ");
  115.                                                 PrintDosError(IoErr());
  116.                                             }
  117.                                         }
  118.                                         else
  119.                                         {
  120.                                             printf("client failait.\n");
  121.                                         }
  122.                                     }
  123.                                     else
  124.                                     {
  125.                                         printf("can't write rexx.tempfile, ");
  126.                                         PrintDosError(IoErr());
  127.                                     }
  128.                                 }
  129.                                 else
  130.                                 {
  131.                                     printf("can't write rexx.tempfile, ");
  132.                                     PrintDosError(IoErr());
  133.                                 }
  134.                             }
  135.                             else
  136.                             {
  137.                                 printf("can't read %s, ",ProgramName);
  138.                                 PrintDosError(IoErr());
  139.                             }
  140.                             if (iobuffer)FreeVec(iobuffer);
  141.                         }
  142.                         else
  143.                             printf("can't read %s, not anouth memory\n",ProgramName);
  144.                     }
  145.                     else
  146.                     {
  147.                         printf("can't read %s, ",ProgramName);
  148.                         PrintDosError(IoErr());
  149.                     }
  150.                     sprintf(buffer,"delete %s quiet",tempfile);
  151.                     Execute(buffer,0,0);
  152.                 }
  153.                 else
  154.                 {
  155.                     if (!in)
  156.                     {
  157.                         printf("can't open %s, ",ProgramName);
  158.                         PrintDosError(IoErr());
  159.                     }
  160.                     else
  161.                     {
  162.                         printf("can't open %s, ",tempfile);
  163.                         PrintDosError(IoErr());
  164.                     }
  165.                 }
  166.                 if (in)Close(in);
  167.                 if (out)Close(out);
  168.                     
  169.             }
  170.             else
  171.             {
  172.                 if (!replyport)printf("can't create rexx-replyport.\n");
  173.                 if (!clientport)printf("can't find clientport.\n");
  174.                 if (!rexxport)printf("can't find client-rexxport.\n");
  175.             }        
  176.         }
  177.     }
  178.     else
  179.         printf("START_REXX ClientID ProgramName\n");
  180.     if (replyport)DeleteMsgPort(replyport);
  181.     Exit(returncode);
  182. }
  183.  
  184.  
  185.  
  186.  
  187.  
  188.